//
//  CYDottedLine.m
//  cyjf
//
//  Created by tauCross on 2018/1/29.
//  Copyright © 2018年 Auto Financing. All rights reserved.
//

#import "CYDottedLine.h"



@implementation CYDottedLine

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetLineWidth(context, self.lineWidth);
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
    CGFloat *lengths = malloc(self.lengths.count * sizeof(CGFloat));
    for(NSInteger i = 0; i < self.lengths.count; i ++)
    {
        *(lengths + i) = [self.lengths[i] doubleValue];
    }
    CGContextSetLineDash(context, self.phase, lengths,self.lengths.count);
    free(lengths);
    CGContextMoveToPoint(context, self.startPoint.x, self.startPoint.y);
    CGContextAddLineToPoint(context, self.endPoint.x, self.endPoint.y);
    CGContextStrokePath(context);
    CGContextClosePath(context);
}

@end
